import {
	BASE_URL
} from "../utils/request.js"

const user_info = uni.getStorageSync('user_info');

export function uploadFile(tempFilePaths) {
  const uploadPromises = tempFilePaths.map((filePath) => {
    return new Promise((resolve, reject) => {
      wx.uploadFile({
        url: BASE_URL + `api.php?m=Api&c=Common&a=uploadFile`,
        filePath: filePath,
        name: 'file',
        formData: {
          token: user_info.token,
        },
        success: (results) => {
          const file = JSON.parse(results.data).data;
          resolve(file); // 上传成功，返回 file
        },
        fail: (err) => {
          reject(err); // 上传失败，返回错误
        },
      });
    });
  });

  return Promise.all(uploadPromises); // 返回所有上传结果的 Promise
}